package m202405.d11;

/**
 * @author: 爱做梦的锤子
 * @date: 2024/5/11 12:29
 */
public class Q283 {

    public static void main(String[] args) {
        Q283 q283 = new Q283();
        q283.moveZeroes(new int[]{0, 1, 0, 3, 12});
    }

    public void moveZeroes(int[] nums) {
        int zeroStart = -1;
        int zeroEnd = -1;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 0) {
                if (zeroEnd < 0) {
                    zeroStart = i;
                    zeroEnd = i;
                } else {
                    zeroEnd += 1;
                }
            } else {
                if (zeroEnd < 0) {
                    continue;
                }
                nums[zeroStart] = nums[i];
                nums[i] = 0;
                zeroEnd += 1;
                zeroStart += 1;
            }
        }
    }
}
